package cn.iocoder.yudao.module.crossborder.order.service.ordershipmentitem;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.crossborder.order.controller.admin.ordershipmentitem.vo.*;
import cn.iocoder.yudao.module.crossborder.order.dal.dataobject.ordershipmentitem.OrderShipmentItemDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.crossborder.order.dal.mysql.ordershipmentitem.OrderShipmentItemMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.crossborder.order.enums.ErrorCodeConstants.*;

/**
 * 跨境电商发货明细 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class OrderShipmentItemServiceImpl implements OrderShipmentItemService {

    @Resource
    private OrderShipmentItemMapper orderShipmentItemMapper;

    @Override
    public Long createOrderShipmentItem(OrderShipmentItemSaveReqVO createReqVO) {
        // 插入
        OrderShipmentItemDO orderShipmentItem = BeanUtils.toBean(createReqVO, OrderShipmentItemDO.class);
        orderShipmentItemMapper.insert(orderShipmentItem);

        // 返回
        return orderShipmentItem.getId();
    }

    @Override
    public void updateOrderShipmentItem(OrderShipmentItemSaveReqVO updateReqVO) {
        // 校验存在
        validateOrderShipmentItemExists(updateReqVO.getId());
        // 更新
        OrderShipmentItemDO updateObj = BeanUtils.toBean(updateReqVO, OrderShipmentItemDO.class);
        orderShipmentItemMapper.updateById(updateObj);
    }

    @Override
    public void deleteOrderShipmentItem(Long id) {
        // 校验存在
        validateOrderShipmentItemExists(id);
        // 删除
        orderShipmentItemMapper.deleteById(id);
    }

    @Override
        public void deleteOrderShipmentItemListByIds(List<Long> ids) {
        // 删除
        orderShipmentItemMapper.deleteByIds(ids);
        }


    private void validateOrderShipmentItemExists(Long id) {
        if (orderShipmentItemMapper.selectById(id) == null) {
            throw exception(ORDER_SHIPMENT_ITEM_NOT_EXISTS);
        }
    }

    @Override
    public OrderShipmentItemDO getOrderShipmentItem(Long id) {
        return orderShipmentItemMapper.selectById(id);
    }

    @Override
    public PageResult<OrderShipmentItemDO> getOrderShipmentItemPage(OrderShipmentItemPageReqVO pageReqVO) {
        return orderShipmentItemMapper.selectPage(pageReqVO);
    }

}